/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.uoc.tdp.pac4.only5.gui.client.panels;

import edu.uoc.tdp.pac4.only5.tools.ResourceBundleTool;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 *
 * @author Gerard
 */
public abstract class AbstractPanel extends JPanel {
    
    private ResourceBundleTool resourceBundleTool;
    
    public AbstractPanel() {
        super();
        resourceBundleTool = ResourceBundleTool.getInstance();
    }

    /**
     * Metode per la internacionalitzacio
     * @param key
     * @return 
     */
    protected String getText(String key){
        return resourceBundleTool.getText(key);
    }
    
    /**
     * Metode per mostrar els errors dialogs amb internacionalitzacio.
     * @param component compoment swing
     * @param key del properties
     */
    protected void showErrorMessageDialog(JComponent component, String key){
        JOptionPane.showMessageDialog(component, getText(key), "Error", JOptionPane.ERROR_MESSAGE);
    }
    
    protected void showMessageDialog(JComponent component, String key){
        JOptionPane.showMessageDialog(component, getText(key), "OK", JOptionPane.INFORMATION_MESSAGE);
    }
    
    protected int showOptionDialog(JComponent component, String key) {
        Object[] options={"Sí","No"};
        int i = JOptionPane.showOptionDialog(component, key, "Question", WIDTH, WIDTH, null, options, this);
        return i;
    }
    
    protected abstract void setLabels();

    protected ResourceBundleTool getResourceBundleTool() {
        return resourceBundleTool;
    }
    
    protected void setTableHeaders(String[] headers, javax.swing.JTable table) {
        String[] traducedHeaders = getResourceBundleTool().getHeaders(headers);
        for (int i = 0; i < traducedHeaders.length; i++) {
            table.getColumnModel().getColumn(i).setHeaderValue(traducedHeaders[i]);
        }
    }
    
    
}
